@extends('layout.default')

@section('layout.content')

<div class="row">
    <div class="col-xs-12 align-right">
      <div style="margin-bottom: 15px;">
        <button class="btn btn-lg btn-danger dialog"><i class="ace-icon fa fa-pencil-square-o"></i>新增培训计划</button>
      </div>
    </div>
  </div><!-- /.row -->

  <div class="row">
    <div class="col-xs-12">
      <table class="table table-hover table-striped table-bordered">
        <thead>
        <tr>
          <th class="center"style="width:120px;">培训类型</th>
          <th class="center"style="width:120px;">所属分支</th>
          <th class="align-middle">学期计划</th>
          <th class="center"style="width:80px;">开设门类</th>
          <th class="center"style="width:80px;">开设班级</th>
          <th class="center"style="width:80px;">计划招生</th>
          <th class="center"style="width:80px;">已报名</th>
          <th class="center"style="width:80px;">已录取</th>
        </tr>
        </thead>
        <tbody>
          @foreach ($typies as $type)
          <?php
            $termsCount = count($type->terms);
            if($termsCount <= 0) $termsCount = 1;
            $rowspan = $termsCount == 1 ? '' : "rowspan='{$termsCount}'";
            $term = $type->terms->shift();
          ?>
            <tr class="">
              <td class="center"{!! $rowspan !!}>{{ $type->name }}</td>
              <td class="center">{{ isset($term)?($term->branch->name):'' }}</td>
              <td class="align-middle train">
                @if(isset($term))
                <a href="{{route('train.category.index',$term->id)}}">
                  {{ isset($term)?($term->name):'' }}
                </a>
                <div class="pull-right operate">
                  <a href="javascript:;" class="blue edit-term" data-id="{{$term->id}}"><i class="ace-icon fa fa-pencil"></i></a>
                  @if(count($term->users)<=0)
                  <a href="javascript:;" class="red"><i class="ace-icon fa fa-times-circle"></i></a>
                  @endif
                </div>
                @endif

              </td>
              <td class="center">{{ isset($term)?count($term->categories):''}}</td>
              <td class="center">{{ isset($term)?count($term->clases):'' }}</td>
              <td class="center">{{ isset($term)? $term->clases->sum('number'):'' }}</td>
              <td class="center b" >
                @if(isset($term))
                <a href="{{route("train.users",$term->id)}}">{{count($term->users)}}</a>
                @endif
              </td>
              <td class="center">{{ isset($term)?count($term->admits):'' }}</td>
            </tr>
            @if($rowspan != '')
              @foreach($type->terms as $term)
              <tr class="">
                <td class="center">{{ $term->branch->name}}</td>
                <td class="align-middle train">
                  <a href="{{route('train.category.index',$term->id)}}">{{ $term->name}}</a>
                  <div class="pull-right operate">
                    <a href="javascript:;"  class="blue edit-term" data-id="{{$term->id}}"><i class="ace-icon fa fa-pencil"></i></a>
                    @if(count($term->users)<=0)
                    <a href="javascript:;" class="red"><i class="ace-icon fa fa-times-circle"></i></a>
                    @endif
                  </div>
                </td>
                <td class="center">{{ count($term->categories) }}</td>
                <td class="center">{{ count($term->clases) }}</td>
                <td class="center">{{ $term->clases->sum('number') }}</td>
                <td class="center b" ><a href="{{route("train.users",$term->id)}}">{{ count($term->users) }}</a></td>
                <td class="center">{{ count($term->admits) }}</td>
              </tr>
              @endforeach
            @endif

          @endforeach
        </tbody>
      </table>
    </div>

  </div>

@stop

@section('javascript')

  <script src="//cdn.bootcss.com/jquery-validate/1.19.1/jquery.validate.min.js"></script>
  <script src="{{URL::asset('assets/js/jquery-validate-methods.js')}}"></script>
  <script src="//cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.js"></script>

  <script type="text/javascript">
    $(function () {

      $('.dialog').on('click', function(e) {

        layer.open({
          type: 2,
          title: '新增培训计划',
          area: ['360px', '480px'],
          shade: 0.8,
          content: "{{route('train.create')}}",
        });

      });


      $('.edit-term').on('click', function(e) {
        var id = $(this).data('id');
        var uri = "/train/"+id+"/edit/";
        layer.open({
          type: 2,
          title: '修改名称',
          area: ['360px', '480px'],
          shade: 0.8,
          content: uri,
        });

      });


      $('.train').on('mouseenter', function () {
          $(this).find('.operate').show();
      }).on('mouseleave', function () {
          $(this).find('.operate').hide();
      });


    });
  </script>
@stop
